home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Web Graphics with Shout 3D
/
Interactive Web Graphics With Shout 3D.iso
/
mac
/
Code
/
Chapter09
/
BackForthPanel.java
< prev
next >
Wrap
Text File
|
2000-08-27
|
1KB
|
60 lines
package applets;
import shout3d.*;
import shout3d.core.*;
import shout3d.math.*;
public class BackForthPanel extends Shout3DPanel implements RenderObserver{
Transform t;
float xPos;
float speed = 1.0f; //in meters per second
float limit = 3.0f;
public BackForthPanel (Shout3DApplet applet){
super(applet);
}
public void customInitialize() {
getRenderer().addRenderObserver(this, null);
t = (Transform) getNodeByName("trans");
xPos = t.translation.getValue()[0];
}
protected void finalize() {
getRenderer().removeRenderObserver(this);
}
public void onPreRender (Renderer r, Object o) {
float xDelta = speed/getFramesPerSecond();
xPos = xPos + xDelta;
if (xPos >= limit || xPos <= -limit) {
speed = -speed;
}
t.translation.set1Value(0, xPos);
}
public void onPostRender (Renderer r, Object o) {
}
} //end of class